"""
认证相关的Pydantic模式定义
"""

from pydantic import BaseModel, EmailStr
from typing import Optional
from datetime import datetime


class UserLogin(BaseModel):
    """用户登录请求模式"""
    username: str
    password: str


class UserRegister(BaseModel):
    """用户注册请求模式"""
    username: str
    email: EmailStr
    password: str
    role: Optional[str] = "user"


class Token(BaseModel):
    """令牌响应模式"""
    access_token: str
    token_type: str = "bearer"
    expires_in: int
    user_info: "UserInfo"


class UserInfo(BaseModel):
    """用户信息模式"""
    id: int
    username: str
    email: str
    role: str
    created_at: datetime
    
    class Config:
        from_attributes = True


class TokenPayload(BaseModel):
    """令牌载荷模式"""
    sub: Optional[str] = None  # subject (user_id)
    username: Optional[str] = None
    role: Optional[str] = None
    exp: Optional[int] = None  # expiration time


class PasswordChange(BaseModel):
    """密码修改请求模式"""
    old_password: str
    new_password: str


class PasswordReset(BaseModel):
    """密码重置请求模式"""
    email: EmailStr


# 更新Token模式的前向引用
Token.model_rebuild()
